package demo.struts2;

import java.util.ArrayList;

import com.opensymphony.xwork2.ActionSupport;

import DAO.ControlDB;
import Entity.Contact;
public  class SearchAction extends ActionSupport {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String firstname;
    private String surname;
    private int id;
    public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	private boolean isactive;
	private int pagenumber=1;
    private int totalpage;
    private int PAGE_SIZE=5;
    ArrayList<Contact> listContact;
    public int getTotalpage() {
		return totalpage;
	}

	public void setTotalpage(int totalpage) {
		this.totalpage = totalpage;
	}

	
    public int getPAGE_SIZE() {
		return PAGE_SIZE;
	}

	public void setPAGE_SIZE(int pAGE_SIZE) {
		PAGE_SIZE = pAGE_SIZE;
	}

	public int getPagenumber() {
		return pagenumber;
	}

	public void setPagenumber(int pagenumber) {
		this.pagenumber = pagenumber;
	}


	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	
    
	public String getFirstname() {
		return firstname;
	}

	public ArrayList<Contact> getListContact() {
		return listContact;
	}

	public void setListContact(ArrayList<Contact> listContact) {
		this.listContact = listContact;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}
	public boolean getIsactive() {
		return isactive;
	}

	public void setIsactive(boolean isactive) {
		this.isactive = isactive;
	}

	@Override
	public String execute() throws Exception {
		System.out.println(isactive);
		ControlDB con=new ControlDB();
		if(firstname.equals("")&&surname.equals("")){
			return "error";
		}else
	    if(isactive==true){
	    	totalpage=con.totalFields(firstname,surname);
	    	listContact= con.getSearchName(surname, firstname,pagenumber,PAGE_SIZE);
	    	
	    }else{
	    	totalpage=con.totalFields(firstname,surname,isactive);
		listContact= con.getSearchName(surname, firstname,pagenumber,PAGE_SIZE,isactive);
	    }
	
		if (listContact==null){
			return "error";
		}else{
			return "success";
		}
		
	}
	
}
//if (this.username.equals("admin") 
//����������������&& this.password.equals("admin123")) {
//������������return "success";
//��������} else {
//������������return "error";
//��������}
//����}